import {BASE_URL} from '../config/config';

class Http {
  get(url, params, method = 'GET') {
    this.post(url, params, method)
  }

  /**
   * post请求
   * @param url：请求地址
   * @param params：请求参数
   * @param method：请求方式
   * @returns {Promise}
   */
  post(url, params, method = 'POST') {

    return new Promise((resolve, reject) => {
      fetch(url, {
        method,
        headers: {
          'Content-Type': 'application/json;charset=utf-8',
        },
        body: JSON.stringify(params)
      })
        .then((response) => {
          console.log('response', response);

          if (response && response.status) {
            switch (response.status) {
              case 200:
                break;
              case 400:
                break;
              case 401:
                break;
            }
          }
          return response.json();
        })
        .then((responseJson) => {
          console.log(123, responseJson);
          resolve(responseJson)
        })
        .catch((error) => {
          console.error(error)
          reject(error)
        })
    })
  }
}

export default new Http()
